<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<title>二分法</title>
	<script type="text/javascript">
		// 12
		var nums = [5, 7, 10, 12, 14, 16, 24, 43, 55, 56, 72, 456];

		function toTwo(arr,num){
			var min = 0;
			var max = arr.length-1;// 11
			var mid = parseInt((min+max)/2);// 5.5  => 5

			while(min <= max){
				if( arr[mid] == num ){
					return mid;
					break;
				}else if( arr[mid] < num ){
					min = mid+1
					mid = parseInt((min+max)/2);
				}else if(arr[mid] > num){
					max = mid-1;
					mid = parseInt((min+max)/2);
				}
			}
			return -1;
		}
		
		
	</script>
</head>
<body>

</body>
</html>